window.passgen = function(chars) {
	function getSymbFrom(symb) {
		var r = Math.random();
		var l = symb.length - 1;
		var x = r * l;
		var i = Math.round(x);
		return symb.charAt(i);
	}

	function getSymb() {
		var symb = "!@#$%^&*_-+=";
		return getSymbFrom(symb);
	}

	function getConsonant() {
		var symb = "wrtplkhgfdszxcvbnm";
		return getSymbFrom(symb);
	}

	function getVovel() {
		var symb = "eyuioaj";
		return getSymbFrom(symb);
	}

	function getNumber() {
		var symb = "0123456789";
		return getSymbFrom(symb);
	}

	function getByTemplate(tpl) {
		var ret = '';
		var sym = '';
		var psym = '';
		for(var i=0;i<tpl.length;i++) {
		    switch(tpl.charAt(i)) {
		        case 's': 
		            sym = getSymb();
		            break;
		        case 'c': 
		            sym = getConsonant();
		            break;
		        case 'v': 
		            sym = getVovel();
		            break;
		        case 'n': 
		            sym = getNumber();
		            break;
		    }
		    if (sym == psym) {
		    	i--; 
		    	continue;
		    }
		    psym = sym;
		    ret += sym;
		}
		return ret;
	}
	
	function genTemplate(chars) {
		var symbs = 'scvn';
		var temp = '';
		for(var i=0; i<chars;i++) {
			temp += getSymbFrom(symbs);
		}
		return temp;
	}
	if (typeof chars == 'string') return getByTemplate(chars);
	
	return getByTemplate(genTemplate(chars));
};

